package com.sr.service.impl;

import com.sr.ibase.IBaseService;
import com.sr.ibase.impl.BaseServiceImpl;
import com.sr.pojo.WMember;
import com.sr.service.IMemberService;
import com.sr.vo.req.MemberReqVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author xiaochi
 * @date 2022/4/30 11:45
 * @desc MemberServiceImpl
 */
@Service
public class MemberServiceImpl extends BaseServiceImpl<WMember> implements IMemberService {

    /**
     * 判断会员账号是否存在
     * @param reqVo
     * @return
     */
    public boolean hasExistsByName(MemberReqVo reqVo){
        IBaseService.Criteria<WMember> criteria = this.createCriteria(WMember.class);
        criteria.andEqualTo(WMember::getUsername,reqVo.getUsername())
                .andNotEqualTo(WMember::getId,!StringUtils.isEmpty(reqVo.getId()),reqVo.getId());
        return this.count(criteria) > 0;
    }
}
